package com.bkgy.modularbx.furnaceTemperature.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modularbx.furnaceTemperature.dao.FurnaceTemperatureDao;
import com.bkgy.modularbx.furnaceTemperature.domain.FurnaceTemperature;
import com.bkgy.modularbx.furnaceTemperature.domain.ModeL1630;
import com.bkgy.modularbx.furnaceTemperature.mapper.FurnaceTemperatureMapper;
import com.bkgy.modularbx.furnaceTemperature.mapper.ModeL1630Mapper;
import com.bkgy.modularbx.furnaceTemperature.service.FurnaceTemperatureService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FurnaceTemperatureServiceImpl extends ServiceImpl<FurnaceTemperatureMapper, FurnaceTemperature>
        implements FurnaceTemperatureService {

    @Resource
    private FurnaceTemperatureDao furnaceTemperatureDao;

    @Autowired
    private ModeL1630Mapper modeL1630Mapper;

    @Override
    public ResultData<FurnaceTemperature> getFurnaceTemperatureData() {
        List<FurnaceTemperature> furnaceTemperatures = furnaceTemperatureDao.getFurnaceTemperature();
        return ResultData.ResultDataSuccess(furnaceTemperatures, null);
    }

    @Override
    public ModeL1630 getFurnaceSet() {
        try {
            LambdaQueryWrapper<ModeL1630> wrapper = new LambdaQueryWrapper<>();
            wrapper.orderByDesc(ModeL1630::getTimeStamp).last("FETCH FIRST 1 ROWS ONLY");
            return modeL1630Mapper.selectOne(wrapper);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
